<?php

if (!defined('IN_XLP')) {
    exit('Access Denied!');
}

/**
 * Description of reportAction
 *
 * @author xlp
 */
class reportAction extends commonAction {

    function __construct() {
        parent::__construct();
        parent::_checkLogin();
        $this->status = array(0 => '<span class="red">未处理</span>', 1 => '核实有效举报', 2 => '<span class="grey">举报有误</span>');
    }

    function index() {
        $p = $this->_getid('p', 1);
        $uid = $this->_getid('uid', 0);
        $fuid = $this->_getid('fuid', 0);
        $status = $this->_getid('status', 0);
        $fmod = $this->_getid('fmod', 0);
        $where = array();
        if ($uid) {
            $where = array('uid' => $uid);
        }
        if ($fuid) {
            $where = array('fuid' => $fuid);
        }
        if ($fmod) {
            $where = array('fmod' => $fmod);
        }
        if ($status) {
            $where = array('status' => ($status - 1));
        }
        $list = C('mod');
        $rs = M('user_report')->where($where)->page($p)->order('id DESC')->findAll();
        $total = M('user_report')->getTotal();
        if ($rs) {
            foreach ($rs as $k => $v) {
                $rs[$k]['mod_name'] = $list[$v['fmod']]['title'];
                $rs[$k]['url'] = $list[$v['fmod']]['url'] . '&' . $list[$v['fmod']]['key'] . '=' . $v['rid'];
                $rs[$k]['user_name'] = getUser($v['uid']);
                $rs[$k]['f_name'] = getUser($v['fuid']);
            }
        }
        $this->assign(array('rs' => $rs, 'total' => $total, 'p' => $p, 'status' => $this->status, 'list' => $list));
//        print_r($this->getAllVar());
        $this->display();
    }

    function setting() {
        $id = $this->_postid('id');
        if (!$id) {
            showError('参数丢失');
        }
        $rs = M('user_report')->where(array('id' => $id))->find();
        if (!$rs) {
            showError('记录不存在');
        }
        $objData = array(
            'admin_id' => admin::$adminInfo['id'],
            'recontent' => $this->_post('recontent'),
            'status' => $this->_postid('status', 0),
            'retime' => TIME
        );
        M('user_report')->update($objData, array('id' => $id));
        $this->JsonReturn('ok', null, 1);
    }

    function delete() {
        $id = $this->_postid('id');
        if (!$id) {
            showError('参数丢失');
        }
        $rs = M('user_report')->where(array('id' => $id))->find();
        if (!$rs) {
            showError('记录不存在');
        }
        M('user_report')->delete(array('id' => $id));
        $this->JsonReturn('ok', null, 1);
    }

}
